﻿using System;
using System.Reflection;
using log4net;

namespace Truncation.Detector.Windows
{
    public class Summary
    {
        private readonly static string Version = Assembly.GetEntryAssembly().GetName().Version.ToString();
        private readonly static string Name = Assembly.GetEntryAssembly().GetName().Name;
        private static readonly ILog Log = LogManager.GetLogger("Summary.Reporter");
        private int _counts;
        private int _errors;
        private int _warnings;
        private int _items;
        private readonly static DateTime StartDateTime = DateTime.Now;
        private static Summary _instance;
        public static Summary Instance
        {
            get { return _instance ?? (_instance = new Summary()); }
        }

        internal static Summary Initialize()
        {
            return Instance;
        }

        private Summary()
        {
            _counts = 0;
            _errors = 0;
            _warnings = 0;
            _items = 0;
        }
        public int Counts
        {
            get { return _counts; }
            set { _counts = value; }
        }

        public int Errors
        {
            get { return _errors; }
            set { _errors = value; }
        }

        public int Warnings
        {
            get { return _warnings; }
            set { _warnings = value; }
        }

        public int Items
        {
            get { return _items; }
            set { _items = value; }
        }

        internal static void UnInitialize()
        {
            DateTime endDateTime = DateTime.Now;
            Log.InfoFormat("{0},{1},{2},{3},{4},{5},{6},{7}", _instance.Counts, _instance.Errors, _instance.Warnings, _instance.Items, StartDateTime.ToString("HH:mm:ss"), endDateTime.ToString("HH:mm:ss"), Name, Version);
        }
    }
}